package com.cssy.xxkj.basic.web;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.cssy.base.web.BaseController;
import com.cssy.base.web.BodyMsg;
import com.cssy.xxkj.basic.entity.BasicSyEnumDO;
import com.cssy.xxkj.basic.service.IBasicSyEnumService;
import com.plat.helper.JqGridHandler;
import com.plat.helper.SearchCondition;
import com.plat.helper.SearchConditions;
import com.plat.helper.SearchResult;
import com.plat.util.GlobalResLoader;
import com.plat.util.SessionUtil;
import com.plat.util.json.AjaxUtil;
import com.plat.util.json.OutJsonGrid;
/**
 * 字典表数据管理
 * @author hf
 *
 */
@Controller
@RequestMapping("/basic/syenum")
public class SyEnumController extends BaseController<BasicSyEnumDO> {
	@Resource(name = "basicSyEnumService")
	private IBasicSyEnumService basicSyEnumService;

	public String manager(HttpServletRequest request, Model model)
			throws Exception {
		return null;
	}
	
	//返回BOM关联原材料物料类型
	@RequestMapping(value = "/materlist")
	public void materlist(HttpServletRequest request, HttpServletResponse response) throws Exception {
		 SearchConditions scs = new SearchConditions();
		 scs.setRemovedProperty("removed");
		 scs.addCondition("zd003Type","MLX",SearchCondition.OP_EQUAL);
		 SearchResult result= basicSyEnumService.findListByExample(scs);
		 List<BasicSyEnumDO> list =result.getResults();
		 if(list==null||list.isEmpty()||list.size()==0){
			 AjaxUtil.printJSonStr(response, "var ItemMLXList ={}");
		 }else{
			 AjaxUtil.printJSonStr(response, "var ItemMLXList ="+JSONObject.toJSONString(list));
		 }
	}
	
	@Override
	public void list(HttpServletRequest request, HttpServletResponse response)
			throws Exception {
//		 JqGridHandler hander=new JqGridHandler(request);
//		 SearchConditions scs = new SearchConditions();
//		 hander.getWheres(scs);
//		 scs.setRemovedProperty(null);
//		 SearchResult result= basicSyEnumService.findListByExample(scs);
//		 OutJsonGrid out=new OutJsonGrid(result);
//		 out.printJSon(response);

	}

	@Override
	public String operationForm(HttpServletRequest request,
			@PathVariable String id, @PathVariable String flag, Model model)
			throws Exception {
		return null;
	}
	
	@Override
	public Map<String, Object> save(HttpServletRequest request,
			BasicSyEnumDO curAP, BindingResult result, Model model) {
		BodyMsg bodyMap = BodyMsg.getInstance();
//		try {
//			if (curAP.getId() != null && !"".equals(curAP.getId())) {// 修改
//				basicSyEnumService.update(curAP, SessionUtil.getUser(request));
//				bodyMap.isSuccess();
//				bodyMap.configWebInfor(GlobalResLoader.getOpsuccess());
//				bodyMap.configWebId(curAP.getId());
//			} else {// 新增
//				BasicSyEnumDO cdo = basicSyEnumService.save(curAP,SessionUtil.getUser(request));
//				bodyMap.isSuccess();
//				bodyMap.configWebInfor(GlobalResLoader.getOpsuccess());
//				bodyMap.configWebId(cdo.getId());
//			}
//		} catch (Exception e) {
//			e.printStackTrace();
//			bodyMap.isFail();
//			bodyMap.configWebInfor(GlobalResLoader.getOpfailed()
//					+ e.getMessage());
//		}
		return bodyMap.modelMap;

	}

	@Override
	public Map<String, Object> delete(HttpServletRequest request,
			HttpServletResponse response, Model model) throws Exception {
		BodyMsg bodyMap = BodyMsg.getInstance();
//		try {
//			String isDelete = request.getParameter("isDelete");//标识是否是假删除
//			String ids = request.getParameter("ids");
//			String[] fields=ids.split(",");
//			for(String field : fields){
//				if(isDelete==null||"0".equals(isDelete)){
//					basicSyEnumService.delete(field, SessionUtil.getUser(request));
//				}else{
//					basicSyEnumService.deleteBizRemoved(field);
//				}
//			}
//			bodyMap.isSuccess(GlobalResLoader.getOpsuccess());
//		} catch (Exception e) {
//			e.printStackTrace();
//			bodyMap.isFail(GlobalResLoader.getOpfailed() + e.getMessage());
//		}
		return bodyMap.modelMap;
	}

}
